package com.isoft.uaaservice.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.isoft.uaaservice.bean.SysUser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface SysUserDao extends BaseMapper<SysUser> {
    /*用户注册（限定普通用户）*/
    @Insert("INSERT INTO TMIM_SYSTEM.SYS_USER (\"USERNAME\", \"PASSWORD\", \"PHONE\", \"EMAIL\", \"CREATEDT\", \"PHOTOURL\", \"ISLOCK\") " +
            "VALUES(#{username},#{password},#{phone},#{email},#{createdt},#{photourl},0);" +
            "INSERT INTO TMIM_SYSTEM.SYS_USER_ROLE (\"USERID\", \"ROLEID\")\n" +
            "SELECT \"ID\", 5 FROM TMIM_SYSTEM.SYS_USER WHERE \"USERNAME\" = #{username};")
    public int register(SysUser sysUser);

    /*远程访问提供注册接口（合同工普通员工）*/
    @Insert("INSERT INTO TMIM_SYSTEM.SYS_USER (\"USERNAME\", \"PASSWORD\", \"PHONE\", \"EMAIL\", \"CREATEDT\", \"PHOTOURL\", \"ISLOCK\") " +
            "VALUES(#{username},#{password},#{phone},#{email},#{createdt},#{photourl},0);" +
            "INSERT INTO TMIM_SYSTEM.SYS_USER_ROLE (\"USERID\", \"ROLEID\")\n" +
            "SELECT \"ID\", 4 FROM TMIM_SYSTEM.SYS_USER WHERE \"USERNAME\" = #{username};")
    public int registerRestTemplate (SysUser sysUser);
    /*忘记密码*/
    //1.获取指定用户信息
    @Select("SELECT * FROM TMIM_SYSTEM.SYS_USER WHERE USERNAME=#{username} AND EMAIL = #{email}")
    public SysUser getNewOne(SysUser sysUser);
    //2.修改密码
    @Update("UPDATE TMIM_SYSTEM.SYS_USER SET PASSWORD = #{password} WHERE USERNAME=#{username} AND EMAIL = #{email}")
    public int changePassword(SysUser sysUser);

    /*修改用户密码*/
    @Update("UPDATE TMIM_SYSTEM.SYS_USER SET PASSWORD = #{password} WHERE ID = #{id}")
    public int updatePasswordById(SysUser sysUser);

    /*修改用户头像*/
    @Update("UPDATE TMIM_SYSTEM.SYS_USER SET PHOTOURL = #{photourl} WHERE ID = #{id}")
    public int changeUserPhoto(SysUser sysUser);


    /*账户冻结与启用*/
    @Update("UPDATE TMIM_SYSTEM.SYS_USER SET ISLOCK = #{islock} WHERE USERNAME = #{username}")
    public int freezeAndEnable(String username , Integer islock);


}

